import java.util.Arrays;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-27
 * Time: 9:30
 */
//day16 贪心算法练习 力扣561 数组拆分
public class Main {
    public int arrayPairSum(int[] nums) {
        int maxSum = 0;
        int n = nums.length;
        //1.排序（升序）
       Arrays.sort(nums);
       //2.分组
        for (int i = 0; i < n-1; i += 2) {
            //将每组的最小值相加
            maxSum += nums[i];
        }
        return maxSum;
    }

    public static void main(String[] args) {
        Main main = new Main();
        int[] array1 = {1, 4, 3, 2};
        int[] array2 = {6, 2, 6, 5, 1, 2};
        System.out.println(main.arrayPairSum(array1));
        System.out.println(main.arrayPairSum(array2));
    }
}
